package com.sx.ems.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sx.ems.entity.SysMaterial;
import com.sx.ems.mapper.SysMaterialMapper;
import com.sx.ems.service.SysMaterialService;
import com.sx.ems.utils.PageUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class SysMaterialServiceImpl extends ServiceImpl<SysMaterialMapper, SysMaterial> implements SysMaterialService {

    @Override
    public PageUtils queryMaterialPage(Map<String, Object> params,Long mark) {

        String name = (String) params.get("name");

        int pageNo = Integer.parseInt(params.get("page").toString());
        int pageSize = Integer.parseInt(params.get("limit").toString());


        QueryWrapper<SysMaterial> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(name), "name", name);
        queryWrapper.eq("mark",mark);

        IPage<SysMaterial> page = this.page(new Page<>(pageNo, pageSize), queryWrapper);

        return new PageUtils(page);
    }
}
